<template>
	<view class="">
		<u-sticky><u-tabs :list="list" :is-scroll="false" :current="current" @change="sectionChange"></u-tabs></u-sticky>
		<view class="" v-if="current == 0">
			<view class="content wrap">
				<u-form :model="form" ref="uForm"  :rules="rules">
					<u-form-item label="采摘日期*" label-width="180" left-icon="calendar"><u-input v-model="form.times" placeholder="采摘日期" disabled="true" disabledColor="#b9babc"/></u-form-item>
					
					<u-form-item label="入库仓库*" label-width="180" left-icon="home"><u-input v-model="form.warehouseName" type="select" @click="getw()"/></u-form-item>
					
					<u-form-item label="商品*" label-width="150">
						<u-radio-group v-model="form.goodsName">
							<u-radio 
								@change="radioChange1" 
								v-for="(item, index) in glist" :key="index" 
								:name="item.name"
							>
							{{item.name}}
							</u-radio>
						</u-radio-group>
					</u-form-item>
				</u-form>
				<u-button type="warning" @click="submit">去称重</u-button>
				
				<u-card padding="16">
					<view class="" slot="head">
						<view class="wrap">
							<u-row>
								<u-col span="12" text-align="center">
									<view class="weikaishi3">
										<u-icon name="search" size="30" labelSize="15px" labelColor="#000000" label="库存信息"></u-icon>
									</view>
								</u-col>
							</u-row>
						</view>
					</view>
					<view class="" slot="body">
						<view class="wrap">
							<u-row>
								<u-col span="3" text-align="center">
									<view class="weikaishi4 u-line-1 u-m-t-10">
										<span>仓库名称</span>
									</view>
								</u-col>
								<u-col span="2" text-align="center">
									<view class="weikaishi4 u-line-1 u-m-t-10">
										<span>商品</span>
									</view>
								</u-col>
								<u-col span="2" text-align="center">
									<view class="weikaishi4 u-line-1 u-m-t-10">
										<span>重量</span>
									</view>
								</u-col>
								<u-col span="5" text-align="center">
									<view class="weikaishi4 u-line-1 u-m-t-10">
										<span>生产日期</span>
									</view>
								</u-col>
							</u-row>
							<u-row v-for="(item,index) in dataList" :key="index">
								<u-col span="3" text-align="center">
									<view class=" u-m-t-10 weikaishi4 jinxingzhong">
										<span>{{item.warehouseName}}</span>
									</view>
								</u-col>
								<u-col span="2" text-align="center">
									<view class=" u-m-t-10 weikaishi4 jinxingzhong">
										<span>{{item.goodsName}}</span>
									</view>
								</u-col>
								<u-col span="2" text-align="center">
									<view class=" u-m-t-10 weikaishi4 jinxingzhong">
										<span>{{item.weight}}</span>
									</view>
								</u-col>
								<u-col span="5" text-align="center">
									<view class=" u-m-t-10 weikaishi4 huanghang jinxingzhong">
										<span>{{item.producetime}}</span>
									</view>
								</u-col>
							</u-row>
						</view>
					</view>
				</u-card>
			</view>
		</view>
		<view>
			<u-select v-model="show" :list="wlist" @confirm="confirm"></u-select>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
		<view class="" v-if="current == 1">
			<u-card padding="16" v-for="(item,index) in dataList2" :key="index">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12" text-align="left">
								<view class="u-line-1 u-m-t-2 weikaishi3">
									<span>入库单号：{{item.putNumber}}</span>
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-2 weikaishi">
									<span>时间：{{item.times}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="right">
								<view class="u-line-1 u-m-t-2 weikaishi">
									<span>采摘人编码：{{item.userNumber}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-4">
									<span>入库仓库：</span><span>{{item.warehouseName}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="right">
								<view class="u-line-1 u-m-t-4">
									<span>入库库位：</span><span>{{item.positionNumber}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-4">
									<span>商品：</span><span>{{item.goodsName}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-4">
									<span>入库重量：</span><span>{{item.weight}}</span>
								</view>
							</u-col>
							<u-col span="7" text-align="left">
								<view class="u-line-1 u-m-t-4">
									<span>生产日期：</span><span>{{item.producetime}}</span>
								</view>
							</u-col>
							<u-col span="5" text-align="left">
								<view class="u-line-1 u-m-t-4">
									<span>状态：</span><span>{{item.states}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="foot-butten" slot="foot" v-if="item.states == '已入'">
					<view :class="flex">
						<u-col span="12" text-align="center" @click="revoke(item.id)">
							<view class="u-m-10 yizuofei">
								撤销
							</view>
						</u-col>
					</view>
				</view>
			</u-card>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				flex:'',
				list: [
					{
						name: '采摘入库'
					}, 
					{
						name: '入库查询'
					}
				],
				current: 0,
				dataList:[],
				dataList2: [],
			    pageNo: 1,
			    hasMore: true,
			    orderCount: 0,
				form:{
				    times:'',
				    userNumber:"",
				    userName:"",
					warehouseName:"加工仓",
				    goodsName:"",
				    weight:"",
				},
				wlist:[
					{
						value:"加工仓",
						label:"加工仓"
					},
					{
						value:"次果仓",
						label:"次果仓"
					},
					{
						value:"废果仓",
						label:"废果仓"
					},
				],
				glist:[],
				show:false,
			};
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if(this.current == 1){
				uni.showLoading({
					title: '加载中'
				})
				if (this.hasMore) {
					this.pageNo++ 
					setTimeout(() => {
						this.loadOrder({
						}).then(res => {})
						uni.hideLoading()
					}, 500)
				} else {
					setTimeout(() => {
						uni.hideLoading()
						uni.showToast({
							icon: 'none',
							title: '已经到低了哦',
							duration: 2000
						});
					}, 500)
				}
			}
		},
		onShow() {
			this.refresh()
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			
			let year = new Date().getFullYear();//年
			let month = new Date().getMonth() + 1;//注意！月份是从0月开始获取的，所以要+1;
			let day = new Date().getDate();//日
			this.form.times =  year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day);
			
			this.$http.post('/rest/fruits/findgoodslist',{
			},{
				params: {},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				if(res.data.data.length>0){
					this.form.goodsName = res.data.data[0].goodsName
					for(let item1 of res.data.data) {
						let obj = {}
						obj.name = item1.goodsName
						this.glist.push(obj)
					}
				}
			})
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods:{
			revoke(id) {
				uni.showModal({
					content: '确定撤销吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/fruits/revoke_rk',{
							},{
								params: {id:id},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
									this.refresh()
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			sectionChange(e){
				this.current = e
				this.refresh()
			},
			// 选中某个单选框时，由radio时触发
			radioChange1(e) {
				console.log(e);
			},
			confirm(e) {
				this.form.warehouseName = e[0].label
			},
			getw(){
				this.show = true
			},
			submit() {
				let pick_rk = {}
				pick_rk.times = this.form.times
				pick_rk.warehouseName = this.form.warehouseName
				pick_rk.goodsName = this.form.goodsName
				uni.setStorageSync('pick_rk', pick_rk);
				this.$Router.push({ 
					name: 'pick_rk_weighs'
				})
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				if(this.current == 0){
					this.$http.post('/rest/fruits/findStorageStockSumBySpec',{
					},{
						params: {
						},
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						this.dataList = res.data.data
					})
				} else if(this.current == 1){
					this.pageNo = 1
					this.hasMore = true
					this.loadOrder({
					}).then(res => {
					})
				}
				uni.hideLoading()
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/fruits/findJiagongcangPagelist',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList2 = res.data.data
						} else {
							this.dataList2 = this.dataList2.concat(res.data.data)
						}
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
		}
	}
</script>
<style lang="scss">
	page{
			background-color: #ffffff;
	}
	.wrap {
		padding: 30rpx;
	}
	.weikaishi2{
		font-size: 36rpx;
	}
	.weikaishi3{
		font-size: 32rpx;
	}
	.huanhang{
		word-break:break-all;
	}
</style>
